#include "cgic.h"
#include <glib.h>
extern  char *cgiQueryString;
int cgiMain() {
// cgiQueryString; 只能接收get 请求参数
// 方式2 cgiFormString（参数名，接收数据的数组，数据大小） 可以接收get 和 post请求
char gatewayIp[128];
char location[256];
cgiFormString("gatewayIp",gatewayIp,128);
cgiFormString("location",location,128);

    //把数据保存到ini配置文件中
    //使用配置文件获取路径
     GKeyFile *file=g_key_file_new();
     g_key_file_load_from_file(file,"../config/config.ini",G_KEY_FILE_NONE,NULL);
     gchar* path=g_key_file_get_string(file,"config","deviceInfoPath",NULL);

    GKeyFile *keyfile=g_key_file_new();
    g_key_file_set_string(keyfile,"config","gatewayIp",gatewayIp);
    g_key_file_set_string(keyfile,"config","location",location);
    g_key_file_save_to_file(keyfile,path,NULL);
    g_key_file_free(keyfile);
    g_key_file_free(file);


cgiHeaderContentType("text/html");
	/* Top of the page */
    //给浏览器响应一个html
	fprintf(cgiOut, "<HTML><HEAD> <meta charset =\"UTF-8\">\n");
	fprintf(cgiOut, "<TITLE>cgic 测试</TITLE></HEAD>\n");
	fprintf(cgiOut, "<BODY><H1>操作成功</H1>\n");
    fprintf(cgiOut, "</BODY></html>");






    return 0;

}